package com.gitee.feizns.quickstart.ding.talk.api.top.api.v2.user;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2UserUpdateRequest;
import com.dingtalk.api.response.OapiV2UserUpdateResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 更新用户信息（/topapi/v2/user/update）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/user-information-update">更新用户信息（/topapi/v2/user/update）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/user-information-update">服务端API 通讯录管理 用户管理 更新用户信息</a>
 * @author feizns
 * @since 2025/3/4
 */
public class Update {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param req {@link OapiV2UserUpdateRequest}
     * @return {@link String}
     */
    @SneakyThrows
    public static String execute(String accessToken, OapiV2UserUpdateRequest req) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/update");
        OapiV2UserUpdateResponse resp = Utils.ifErrorThrow(client.execute(req, accessToken));
        return Utils.ifErrorThrow(resp).getBody();
    }

}
